package com.lzx.es.controller;

import com.lzx.common.utils.R;
import com.lzx.es.entity.articleVO.RequestParams;
import com.lzx.es.entity.userVO.QueryUser;
import com.lzx.es.service.ESArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 程序员星星
 * @date 2023/2/9
 * @Description
 */
@RestController
@RequestMapping("/es/web")
public class ESArticleController {
    @Resource
    private ESArticleService esArticleService;

    //用户修改头像或昵称，批量更新数据
    @PutMapping("/article/updateNicknameOrAvatar")
    public R updateNicknameOrAvatar(@RequestBody QueryUser queryUser) {
        return esArticleService.updateNicknameOrAvatar(queryUser);
    }

    //查询文章
    @GetMapping("/getArticle/{articleId}")
    public R getArticle(@PathVariable Long articleId) {
        return esArticleService.getArticle(articleId);
    }

    //修改文章
    @PutMapping("/editArticle/{articleId}")
    public R editArticle(@PathVariable Long articleId) {
        return esArticleService.editArticle(articleId);
    }

    //删除文章
    @DeleteMapping("/deleteArticle/{articleId}")
    public R deleteArticle(@PathVariable Long articleId) {
        return esArticleService.deleteArticle(articleId);
    }

    //添加文章
    @PostMapping("/addArticle/{articleId}")
    public R addArticle(@PathVariable Long articleId) {
        return esArticleService.addArticle(articleId);
    }

    //自动补全
    @GetMapping("/article/suggestion/{key}")
    public R getSuggestion(@PathVariable String key) {
        return esArticleService.getSuggestion(key);
    }

    //将数据重新导入es
    @PostMapping("/saveArticleList")
    public R saveArticleList() {
        return esArticleService.saveArticleList();
    }

    //全文检索
    @PostMapping("/searchArticle")
    public R searchArticle(@RequestBody RequestParams requestParams) {
        return esArticleService.searchArticle(requestParams);
    }
}
